import 'package:flutter_chat/common/service/services.dart';
import 'package:flutter_chat/common/store/stores.dart';
import 'package:get/get.dart';
import 'package:jiffy/jiffy.dart';

class Global {
  /// 初始化
  static Future<void> init() async {
    await Get.putAsync<StorageService>(() => StorageService().init());
    await Get.putAsync<NotificationService>(() => NotificationService().init());
    await Get.putAsync<PackageInfoService>(() => PackageInfoService().init());

    Get.lazyPut(() => UserStore());
    Get.lazyPut(() => WebSocketService());
    Get.lazyPut(() => RetryService());

    await Jiffy.setLocale('zh_cn');
  }

  /// 网络数据初始化
  static Future<void> onInitAsync() async {
    if (UserStore.to.isLogin) {
      /// 更新用户信息
      await UserStore.to.getUserInfo();
    }
  }
}
